//
//  TYHGussLikeTableViewCell.m
//  OpenPractice
//
//  Created by tanyuehong on 18/1/19.
//  Copyright © 2019年  lijinghua. All rights reserved.
//

#import "TYHGussLikeTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface TYHGussLikeTableViewCell ()

 @property (nonatomic,weak)UIView *mySpreateView;
 @property (nonatomic,weak)UILabel *myDscribLaebl;

@end

@implementation TYHGussLikeTableViewCell

+ (instancetype)cellWithtableView:(UITableView *)tableView {
    static NSString *resusedId = @"TYHGusssLiketCellId";
    TYHGussLikeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resusedId];
    if (!cell) {
        cell = [[TYHGussLikeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resusedId];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initAllSubViews];
    }
    return self;
}

- (void)initAllSubViews  {
    UIView *sprateViw = [[UIView alloc] init];
    sprateViw.backgroundColor = kSingleLineViewColor;
    [self.contentView addSubview:sprateViw];
    self.mySpreateView = sprateViw;
    
    self.textLabel.font = [UIFont systemFontOfSize:14];
    self.textLabel.textColor = kTYH333333TextColor;
    
    UILabel *myDscribLaebl = [[UILabel alloc] init];
    myDscribLaebl.font = [UIFont systemFontOfSize:12];
    myDscribLaebl.textColor = kTYH666666TextColor;
    [self.contentView addSubview:myDscribLaebl];
    self.myDscribLaebl = myDscribLaebl;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.mySpreateView.frame = CGRectMake(10, 0, self.width-10, 0.5);
    self.imageView.frame = CGRectMake(10, 10, self.height-20, self.height-20);
    [self.textLabel sizeToFit];
    self.textLabel.top = self.imageView.top;
    self.textLabel.left = self.imageView.right+5;
    
    self.myDscribLaebl.frame = CGRectMake(self.imageView.right+5, self.textLabel.bottom+2.5, self.width-self.imageView.left-20, self.height-10-self.textLabel.bottom-2.5);
    self.myDscribLaebl.numberOfLines = 0;
}

- (void)setItemData:(NSDictionary *)itemData {
    if (_itemData == itemData) {
        return ;
    }
    NSString *imageUrl = [itemData objectForKey:@"imageUrl"];
    if (imageUrl.length>0) {
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil];
    }
    NSString *title = [itemData objectForKey:@"title"];
    if (title.length>0) {
        self.textLabel.text = title;
    } else {
        self.textLabel.text = @"";
    }
    
    NSString *descrb = [itemData objectForKey:@"descrb"];
    if (descrb.length>0) {
        self.myDscribLaebl.text = descrb;
    } else {
        self.myDscribLaebl.text = @"";
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
